package io.adrainty.algorithm.leetcode.normal;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 2785. 将字符串中的元音字母排序
 *
 * @author AdRainty
 * @version V1.0.0
 * @since 2025/9/11 下午11:50
 */
public class Solution2785 {

    public String sortVowels(String s) {
        Set<Character> voewls = Set.of('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U');
        List<Character> vowelList = new ArrayList<>();
        char[] charArray = s.toCharArray();
        for (char c : charArray) {
            if (voewls.contains(c)) {
                vowelList.add(c);
            }
        }
        vowelList.sort(Character::compareTo);
        char[] res = new char[s.length()];
        int cur = 0;
        for (int i = 0; i < charArray.length; i++) {
            char c = charArray[i];
            if (voewls.contains(c)) {
                res[i] = vowelList.get(cur++);
            } else {
                res[i] = c;
            }
        }
        return new String(res);
    }

    public static void main(String[] args) {
        Solution2785 solution2785 = new Solution2785();
        System.out.println(solution2785.sortVowels("lEetcOde"));
    }

}
